<template>
  <div class="charge">
    <!-- 收费件查询 -->
    <Card>
      <Form :model="chargeForm" ref="chargeForm" :rules="rules" style="display: block;">
        <Row gutter="40">
          <i-col span="6">
            <FormItem>
              <Input v-model="chargeForm.policyNo" placeholder="保单号" />
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Input placeholder="投保人姓名" v-model="chargeForm.clerkName" />
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Input placeholder="联系地址" v-model="chargeForm.postaladdress" />
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <DatePicker type="daterange" style="width:100%" placeholder="应交日时间段" v-model="chargeForm.payableDayRange"
                :editable="false"></DatePicker>
            </FormItem>
          </i-col>
        </Row>
        <Row gutter="40">
          <i-col span="6">
            <FormItem>
              <Select v-model="chargeForm.payWay" placeholder="交费方式" @on-change="changePayWay" clearable>
                <Option v-for="item in payWayList" :key="item.key" :value="item.key">{{ item.value }}</Option>
              </Select>
            </FormItem>
          </i-col>
          <i-col span="6">
            <Row>
              <i-col span="11">
                <FormItem prop="premiumMin">
                  <Input v-model="chargeForm.premiumMin" placeholder="最低应收保费" type="number"
                    @on-blur="decimalConversion(chargeForm.premiumMin)" />
                </FormItem>
              </i-col>
              <i-col span="2" style="text-align:center;line-height:30px">-</i-col>
              <i-col span="11">
                <FormItem prop="premiumMax">
                  <Input v-model="chargeForm.premiumMax" placeholder="最高应收保费" type="number"
                    @on-blur="decimalConversion2(chargeForm.premiumMax)" />
                </FormItem>
              </i-col>
            </Row>
          </i-col>
        </Row>
        <Row>
          <Button type="primary" @click="handleSubmit()" style="margin-right:10px" :loading="querySubmit">查询</Button>
          <Button @click="handleReset()">重置</Button>
        </Row>
      </Form>
    </Card>
    <!-- 收费件计划提交 -->
    <Card style="margin-top:15px">
      <Div class="supervise">
        <Form :model="chargePlan" style="display: block;">
          <Row>
            <i-col span="14">
              <Div class="supervise-content">
                <Div class="planTime">计划时间:</Div>
                <Row>
                  <FormItem>
                    <RadioGroup v-model="chargePlan.planTime" @on-change="chargePlanTypeChange">
                      <i-col span="7">
                        <Radio label="应交日前" class="radio-label">
                          <span style="font-weight:normal">
                            应交日前
                            <Input :disabled="chargePlan.beforeDayDisabled" style="width:60px;"
                              v-model="chargePlan.beforeDay" @on-blur="dateValue1" />天
                          </span>
                        </Radio>
                      </i-col>
                      <i-col span="7">
                        <Radio label="应交日后">
                          <span style="font-weight:normal">
                            应交日后
                            <Input :disabled="chargePlan.afterDayDisabled" style="width:60px"
                              v-model="chargePlan.afterDay" @on-blur="dateValue2" />天
                          </span>
                        </Radio>
                      </i-col>
                      <i-col span="10" style="display:flex;">
                        <Radio label="指定日期">
                        </Radio>
                        <span style="font-weight:normal">
                          <DatePicker :editable="false" :disabled="chargePlan.appointedDayDisabled" placeholder="指定日期"
                            v-model="chargePlan.appointedDay" @on-change="dateValue3"></DatePicker>
                        </span>
                      </i-col>
                    </RadioGroup>
                  </FormItem>
                </Row>
              </Div>
            </i-col>
            <i-col span="9">
              <Div class="supervise-content">
                <div class="planTime">工作方式:</div>
                <Select v-model="chargePlan.workType">
                  <Option v-for="item in workType" :key="item.key" :value="item.key">{{ item.value }}</Option>
                </Select>
              </Div>
            </i-col>
            <i-col span="1">
              <div class="confirm">
                <FormItem>
                  <Button type="primary" @click="PlanSubmit()" :loading="planSubmit">
                    确
                    <br />定
                  </Button>
                </FormItem>
              </div>
            </i-col>
          </Row>
        </Form>
      </Div>
      <Table :columns="chargeColumns" :data="chargeData" @on-selection-change="selectionChange"></Table>
      <Page :total="total" show-sizer show-total style="text-align:right;margin-top:20px" @on-change="pageChange"
        @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeOptions" :current="pageIndex" :page-size="pageSize"
        transfer></Page>
    </Card>
    <div class="contain" ref="mybox">
      <canvas id="myCanvas" width="200" height="100" ref="myCanvas" style="position: absolute;"></canvas>
    </div>
  </div>
</template>

<script>
import { drawSign } from '../../../util/drawSign'
export default {
  props: {
    payWayList: {
      type: Array
    }
  },
  data() {
    const validatePremium = (rule, value, callback) => {
      if (value) {
        let reg = /^[0-9][0-9]*$/;
        let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
        let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
        if (reg.test(value)) {
          callback();
        } else if (reg1.test(value)) {
          callback();
        } else if (reg2.test(value)) {
          callback();
        } else {
          callback(new Error("请输入两位小数"));
        }
      } else {
        callback();
      }
      callback();
    };
    return {
      chargeForm: {
        policyNo: "",
        payableDayRange: ["", ""],
        clerkName: "",
        premiumMin: "",
        premiumMax: "",
        postaladdress: "",
        payWay: '',
      },
      chargePlan: {
        planTime: "",
        workType: "",
        beforeDayDisabled: "true",
        beforeDay: "",
        afterDayDisabled: "true",
        afterDay: "",
        appointedDayDisabled: "true",
        appointedDay: "",
        finalPlanTime: ""
      },
      chargeData: [],
      workType: [],
      // 表格数据
      chargeColumns: [
        {
          type: "selection",
          align: "center",
          fixed: "left",
          width: 60
        },
        {
          title: "保单号",
          key: "contno",
          fixed: "left",
          width: 180
        },
        {
          title: "投保人",
          key: "appntname",
          align: "center",
          // sortable: true,
          width: 130
        },
        {
          title: "应交日",
          key: "paytodate",
          align: "center",
          // sortable: true,
          width: 140
        },
        {
          title: "应交次数",
          key: "count",
          align: "center",
          width: 120
        },
        {
          title: "应收保费(元)",
          key: "paymoney",
          align: "center",
          // sortable: true,
          width: 150
        },
        {
          title: "主险",
          key: "mainRisks"
        }
      ],
      rules: {
        premiumMin: [{ validator: validatePremium, trigger: "blur" }],
        premiumMax: [{ validator: validatePremium, trigger: "blur" }]
      },
      total: 0,
      pageSizeOptions: [5, 10, 15, 20],
      pageIndex: 1,
      pageSize: 10,
      pageObj: "",
      selectionData: [],
      querySubmit: false,
      planSubmit: false
    };
  },
  methods: {
    // 表单查询
    handleSubmit(params) {
      this.$refs.chargeForm.validate(valid => {
        if (valid) {
          if (params) {
          } else {
            this.querySubmit = true;
          }
          this.pageIndex = 1;
          this.pageSize = 10;
          let startDate = "";
          let endDate = "";
          if (this.chargeForm.payableDayRange[0]) {
            let date1 = new Date(this.chargeForm.payableDayRange[0]).toJSON();
            startDate = new Date(
              +new Date(date1) + 8 * 3600 * 1000
            ).toISOString();
            let date2 = new Date(this.chargeForm.payableDayRange[1]).toJSON();
            endDate = new Date(
              +new Date(date2) + 8 * 3600 * 1000
            ).toISOString();
          }
          let obj = {
            index: this.pageIndex,
            pageSize: this.pageSize,
            initflag: 0,
            selecttype: 1,
            contno:
              this.chargeForm.policyNo == "" ? null : this.chargeForm.policyNo,
            appntname:
              this.chargeForm.clerkName == ""
                ? null
                : this.chargeForm.clerkName,
            rangeminpaytodate: startDate == "" ? null : startDate,
            rangemaxpaytodate: endDate == "" ? null : endDate,
            rangeminprem:
              this.chargeForm.premiumMin == ""
                ? null
                : this.chargeForm.premiumMin,
            rangemaxprem:
              this.chargeForm.premiumMax == ""
                ? null
                : this.chargeForm.premiumMax,
            postaladdress: this.chargeForm.postaladdress
              ? this.chargeForm.postaladdress
              : null,
            payintv: this.chargeForm.payWay ? this.chargeForm.payWay : null,//交费方式
          };
          this.pageObj = obj;
          this.api.getlist(obj).then(res => {
            res.data = {
              "professionContNums": {
                "contnumsforSupervisor": 61,
                "contnumsforOrphan": 0,
                "contnumsforInvalid": 43
              },
              "baseMapForPlanList": {
                "ldcoms": [
                  {
                    "key": "86",
                    "value": "****人寿",
                    "childern": null
                  },
                  {
                    "key": "860000",
                    "value": "总公司直属机构",
                    "childern": null
                  },
                  {
                    "key": "86000000",
                    "value": "****人寿保险股份有限公司",
                    "childern": null
                  },
                  {
                    "key": "86000001",
                    "value": "****人寿总公司直属支公司",
                    "childern": null
                  },
                  {
                    "key": "8601",
                    "value": "****人寿无锡分公司",
                    "childern": null
                  },
                  {
                    "key": "860101",
                    "value": "****人寿无锡分公司",
                    "childern": null
                  },
                  {
                    "key": "86010101",
                    "value": "****人寿无锡分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86010102",
                    "value": "****人寿江阴支公司",
                    "childern": null
                  },
                  {
                    "key": "86010103",
                    "value": "****人寿宜兴支公司",
                    "childern": null
                  },
                  {
                    "key": "86010104",
                    "value": "****人寿无锡分公司惠山区营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86010105",
                    "value": "****人寿无锡分公司锡山区营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86010106",
                    "value": "****人寿江阴支公司周庄营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86010107",
                    "value": "****人寿无锡分公司综合金融营业部",
                    "childern": null
                  },
                  {
                    "key": "86010108",
                    "value": "****人寿保险股份有限公司无锡市滨湖区支公司",
                    "childern": null
                  },
                  {
                    "key": "86010109",
                    "value": "医惠锡城项目部",
                    "childern": null
                  },
                  {
                    "key": "86010110",
                    "value": "测试T5",
                    "childern": null
                  },
                  {
                    "key": "86010111",
                    "value": "测试T4看看",
                    "childern": null
                  },
                  {
                    "key": "86010112",
                    "value": "测试T4第三",
                    "childern": null
                  },
                  {
                    "key": "86010113",
                    "value": "测试T4第四次",
                    "childern": null
                  },
                  {
                    "key": "86010114",
                    "value": "测试T4第三次",
                    "childern": null
                  },
                  {
                    "key": "86010122",
                    "value": "新建个险机构",
                    "childern": null
                  },
                  {
                    "key": "86010144",
                    "value": "86010144",
                    "childern": null
                  },
                  {
                    "key": "86010158",
                    "value": "新建个险机构",
                    "childern": null
                  },
                  {
                    "key": "86010167",
                    "value": "86010167",
                    "childern": null
                  },
                  {
                    "key": "86010188",
                    "value": "新基本法测试",
                    "childern": null
                  },
                  {
                    "key": "86010199",
                    "value": "86010199",
                    "childern": null
                  },
                  {
                    "key": "860102",
                    "value": "****人寿无锡分公司",
                    "childern": null
                  },
                  {
                    "key": "8602",
                    "value": "****人寿江苏分公司",
                    "childern": null
                  },
                  {
                    "key": "860201",
                    "value": "****人寿南京分公司",
                    "childern": null
                  },
                  {
                    "key": "86020101",
                    "value": "****人寿南京分公司城区营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020102",
                    "value": "****人寿江苏分公司南京市城区营销服务部二区",
                    "childern": null
                  },
                  {
                    "key": "86020103",
                    "value": "****人寿江苏分公司南京市城区营销服务部三区",
                    "childern": null
                  },
                  {
                    "key": "86020104",
                    "value": "****人寿南京分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "860202",
                    "value": "****人寿南通分公司",
                    "childern": null
                  },
                  {
                    "key": "86020201",
                    "value": "****人寿南通分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020202",
                    "value": "****人寿南通分公司海安营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020203",
                    "value": "****人寿南通分公司通州营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020204",
                    "value": "****人寿南通分公司如东营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020205",
                    "value": "****人寿南通分公司营业本部二区",
                    "childern": null
                  },
                  {
                    "key": "860203",
                    "value": "****人寿徐州分公司",
                    "childern": null
                  },
                  {
                    "key": "86020301",
                    "value": "****人寿徐州分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020302",
                    "value": "****人寿徐州分公司铜山区营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020303",
                    "value": "****人寿徐州分公司营业本部三区",
                    "childern": null
                  },
                  {
                    "key": "86020304",
                    "value": "****人寿徐州分公司丰县营销服务部",
                    "childern": null
                  },
                  {
                    "key": "860204",
                    "value": "****人寿泰州分公司",
                    "childern": null
                  },
                  {
                    "key": "86020401",
                    "value": "****人寿泰州分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020402",
                    "value": "****人寿泰州分公司泰兴营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020403",
                    "value": "****人寿泰州分公司姜堰区营销服务部",
                    "childern": null
                  },
                  {
                    "key": "860205",
                    "value": "****人寿盐城分公司",
                    "childern": null
                  },
                  {
                    "key": "86020501",
                    "value": "****人寿盐城分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020502",
                    "value": "****人寿盐城分公司东台营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020503",
                    "value": "****人寿盐城分公司营业本部二区",
                    "childern": null
                  },
                  {
                    "key": "860206",
                    "value": "****人寿苏州分公司",
                    "childern": null
                  },
                  {
                    "key": "86020601",
                    "value": "****人寿苏州分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020602",
                    "value": "****人寿苏州分公司太仓营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020603",
                    "value": "****人寿苏州市昆山支公司",
                    "childern": null
                  },
                  {
                    "key": "860207",
                    "value": "****人寿镇江分公司",
                    "childern": null
                  },
                  {
                    "key": "86020701",
                    "value": "****人寿镇江分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020702",
                    "value": "****人寿镇江分公司丹阳营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020703",
                    "value": "****人寿镇江分公司扬中营销服务部",
                    "childern": null
                  },
                  {
                    "key": "860208",
                    "value": "****人寿扬州分公司",
                    "childern": null
                  },
                  {
                    "key": "86020801",
                    "value": "****人寿扬州分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86020802",
                    "value": "****人寿扬州分公司江都营销服务部",
                    "childern": null
                  },
                  {
                    "key": "86020803",
                    "value": "****人寿扬州分公司高邮营销服务部",
                    "childern": null
                  },
                  {
                    "key": "860209",
                    "value": "****人寿常州分公司",
                    "childern": null
                  },
                  {
                    "key": "86020901",
                    "value": "****人寿常州分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "860210",
                    "value": "****人寿淮安分公司",
                    "childern": null
                  },
                  {
                    "key": "86021001",
                    "value": "****人寿淮安分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86021002",
                    "value": "****人寿淮安分公司淮阴区支公司",
                    "childern": null
                  },
                  {
                    "key": "86021003",
                    "value": "****人寿淮安分公司营业本部三区",
                    "childern": null
                  },
                  {
                    "key": "86021004",
                    "value": "****人寿淮安分公司营业本部四区",
                    "childern": null
                  },
                  {
                    "key": "860211",
                    "value": "新基本法测试",
                    "childern": null
                  },
                  {
                    "key": "8603",
                    "value": "****人寿安徽分公司",
                    "childern": null
                  },
                  {
                    "key": "860301",
                    "value": "****人寿安徽分公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "86030101",
                    "value": "****人寿安徽分公司本部营业区",
                    "childern": null
                  },
                  {
                    "key": "86030102",
                    "value": "86030102",
                    "childern": null
                  },
                  {
                    "key": "86030103",
                    "value": "86030103",
                    "childern": null
                  },
                  {
                    "key": "860302",
                    "value": "****人寿亳州中心支公司",
                    "childern": null
                  },
                  {
                    "key": "86030201",
                    "value": "安徽亳州机构",
                    "childern": null
                  },
                  {
                    "key": "86030202",
                    "value": "86030202",
                    "childern": null
                  },
                  {
                    "key": "860303",
                    "value": "****人寿阜阳中心支公司",
                    "childern": null
                  },
                  {
                    "key": "86030301",
                    "value": "****人寿阜阳中心支公司营业本部",
                    "childern": null
                  },
                  {
                    "key": "860304",
                    "value": "安徽分公司亳州市中心支公司蒙城支公司（筹）",
                    "childern": null
                  },
                  {
                    "key": "86030401",
                    "value": "安徽分公司亳州市中心支公司蒙城支公司（筹）",
                    "childern": null
                  },
                  {
                    "key": "860305",
                    "value": "安徽分公司宿州（筹）",
                    "childern": null
                  },
                  {
                    "key": "86030501",
                    "value": "安徽分公司宿州（筹）",
                    "childern": null
                  },
                  {
                    "key": "860309",
                    "value": "续期4198测试",
                    "childern": null
                  },
                  {
                    "key": "86030901",
                    "value": "续期4198测试",
                    "childern": null
                  },
                  {
                    "key": "8604",
                    "value": "测试",
                    "childern": null
                  },
                  {
                    "key": "860401",
                    "value": "测试",
                    "childern": null
                  },
                  {
                    "key": "86040101",
                    "value": "测试",
                    "childern": null
                  },
                  {
                    "key": "86040102",
                    "value": "86040102",
                    "childern": null
                  },
                  {
                    "key": "860402",
                    "value": "测试",
                    "childern": null
                  },
                  {
                    "key": "86040201",
                    "value": "测试",
                    "childern": null
                  },
                  {
                    "key": "8605",
                    "value": "****人寿湖北分公司",
                    "childern": null
                  },
                  {
                    "key": "860501",
                    "value": "****人寿湖北分公司武汉本部",
                    "childern": null
                  },
                  {
                    "key": "86050101",
                    "value": "****人寿湖北分公司武汉本部一区",
                    "childern": null
                  },
                  {
                    "key": "86050102",
                    "value": "****人寿湖北分公司武汉本部二区",
                    "childern": null
                  },
                  {
                    "key": "86050103",
                    "value": "****人寿湖北分公司武汉本部三区",
                    "childern": null
                  },
                  {
                    "key": "860502",
                    "value": "测试本部二区",
                    "childern": null
                  },
                  {
                    "key": "86050201",
                    "value": "测试本部二区营业本部",
                    "childern": null
                  },
                  {
                    "key": "8606",
                    "value": "筹备省分公司",
                    "childern": null
                  },
                  {
                    "key": "860601",
                    "value": "筹备三级分公司",
                    "childern": null
                  },
                  {
                    "key": "86060101",
                    "value": "筹备营销服务部",
                    "childern": null
                  },
                  {
                    "key": "8607",
                    "value": "佣金考勤分公司",
                    "childern": null
                  },
                  {
                    "key": "860701",
                    "value": "佣金考勤中心支公司",
                    "childern": null
                  },
                  {
                    "key": "86070101",
                    "value": "佣金营销服务部",
                    "childern": null
                  },
                  {
                    "key": "8608",
                    "value": "续期管理机构专用分公司",
                    "childern": null
                  },
                  {
                    "key": "860801",
                    "value": "续期专用支公司1",
                    "childern": null
                  },
                  {
                    "key": "86080101",
                    "value": "续期专用营业部1",
                    "childern": null
                  },
                  {
                    "key": "860802",
                    "value": "续期专用支公司2",
                    "childern": null
                  },
                  {
                    "key": "86080201",
                    "value": "续期专用营业部2",
                    "childern": null
                  },
                  {
                    "key": "860803",
                    "value": "续期专用支公司3",
                    "childern": null
                  },
                  {
                    "key": "86080301",
                    "value": "续期专用营业部3",
                    "childern": null
                  },
                  {
                    "key": "860804",
                    "value": "续期基本法测试",
                    "childern": null
                  },
                  {
                    "key": "86080401",
                    "value": "续期专用营业部4",
                    "childern": null
                  },
                  {
                    "key": "86080404",
                    "value": "续期专用营业部4",
                    "childern": null
                  },
                  {
                    "key": "8609",
                    "value": "续期考核",
                    "childern": null
                  },
                  {
                    "key": "8610",
                    "value": "8610",
                    "childern": null
                  },
                  {
                    "key": "861001",
                    "value": "861001",
                    "childern": null
                  },
                  {
                    "key": "86100101",
                    "value": "86100101",
                    "childern": null
                  },
                  {
                    "key": "86100102",
                    "value": "86100102",
                    "childern": null
                  },
                  {
                    "key": "8611",
                    "value": "预生产分公司",
                    "childern": null
                  },
                  {
                    "key": "8612",
                    "value": "续期考核",
                    "childern": null
                  },
                  {
                    "key": "861201",
                    "value": "续期考核",
                    "childern": null
                  },
                  {
                    "key": "86120101",
                    "value": "86120101",
                    "childern": null
                  },
                  {
                    "key": "861202",
                    "value": "续期二组",
                    "childern": null
                  },
                  {
                    "key": "86120201",
                    "value": "86120201",
                    "childern": null
                  },
                  {
                    "key": "861203",
                    "value": "续期三组",
                    "childern": null
                  },
                  {
                    "key": "86120301",
                    "value": "续期三组",
                    "childern": null
                  },
                  {
                    "key": "861204",
                    "value": "续期四组",
                    "childern": null
                  },
                  {
                    "key": "86120401",
                    "value": "续期四组",
                    "childern": null
                  },
                  {
                    "key": "861205",
                    "value": "续期五组",
                    "childern": null
                  },
                  {
                    "key": "86120501",
                    "value": "续期五组",
                    "childern": null
                  },
                  {
                    "key": "861206",
                    "value": "续期六组",
                    "childern": null
                  },
                  {
                    "key": "86120601",
                    "value": "续期六组",
                    "childern": null
                  },
                  {
                    "key": "861207",
                    "value": "续期七组",
                    "childern": null
                  },
                  {
                    "key": "86120701",
                    "value": "续期七组",
                    "childern": null
                  },
                  {
                    "key": "861208",
                    "value": "861208",
                    "childern": null
                  },
                  {
                    "key": "86120801",
                    "value": "86120801",
                    "childern": null
                  },
                  {
                    "key": "861209",
                    "value": "续期九组",
                    "childern": null
                  },
                  {
                    "key": "86120901",
                    "value": "续期九组",
                    "childern": null
                  },
                  {
                    "key": "861210",
                    "value": "续期十组",
                    "childern": null
                  },
                  {
                    "key": "86121001",
                    "value": "续期十组",
                    "childern": null
                  },
                  {
                    "key": "861211",
                    "value": "续期十一组",
                    "childern": null
                  },
                  {
                    "key": "86121101",
                    "value": "续期十一组",
                    "childern": null
                  },
                  {
                    "key": "861212",
                    "value": "续期十二组",
                    "childern": null
                  },
                  {
                    "key": "86121201",
                    "value": "续期十二组",
                    "childern": null
                  },
                  {
                    "key": "861213",
                    "value": "续期十三组",
                    "childern": null
                  },
                  {
                    "key": "86121301",
                    "value": "续期十三组",
                    "childern": null
                  },
                  {
                    "key": "861214",
                    "value": "861214",
                    "childern": null
                  },
                  {
                    "key": "86121401",
                    "value": "86121401",
                    "childern": null
                  },
                  {
                    "key": "8615",
                    "value": "8615",
                    "childern": null
                  },
                  {
                    "key": "861501",
                    "value": "861501",
                    "childern": null
                  },
                  {
                    "key": "86150101",
                    "value": "86150101",
                    "childern": null
                  },
                  {
                    "key": "8620",
                    "value": "8620",
                    "childern": null
                  },
                  {
                    "key": "862001",
                    "value": "862001",
                    "childern": null
                  },
                  {
                    "key": "86200101",
                    "value": "86200101",
                    "childern": null
                  },
                  {
                    "key": "8621",
                    "value": "8621",
                    "childern": null
                  },
                  {
                    "key": "862101",
                    "value": "862101",
                    "childern": null
                  },
                  {
                    "key": "86210101",
                    "value": "86210101",
                    "childern": null
                  },
                  {
                    "key": "8622",
                    "value": "上海分公司",
                    "childern": null
                  },
                  {
                    "key": "8625",
                    "value": "8625",
                    "childern": null
                  },
                  {
                    "key": "862501",
                    "value": "862501",
                    "childern": null
                  },
                  {
                    "key": "86250101",
                    "value": "86250101",
                    "childern": null
                  },
                  {
                    "key": "8633",
                    "value": "8633",
                    "childern": null
                  },
                  {
                    "key": "863301",
                    "value": "863301",
                    "childern": null
                  },
                  {
                    "key": "86330100",
                    "value": "86330100",
                    "childern": null
                  },
                  {
                    "key": "8634",
                    "value": "****人寿程程分公司",
                    "childern": null
                  },
                  {
                    "key": "8635",
                    "value": "****人寿8635分公司",
                    "childern": null
                  },
                  {
                    "key": "8644",
                    "value": "基本法分公司",
                    "childern": null
                  },
                  {
                    "key": "864401",
                    "value": "基本法中心支公司",
                    "childern": null
                  },
                  {
                    "key": "86440101",
                    "value": "基本法营销服务部",
                    "childern": null
                  },
                  {
                    "key": "8646",
                    "value": "掌上****基本法",
                    "childern": null
                  },
                  {
                    "key": "864601",
                    "value": "掌上****基本法",
                    "childern": null
                  },
                  {
                    "key": "86460101",
                    "value": "掌上****基本法",
                    "childern": null
                  },
                  {
                    "key": "8655",
                    "value": "测试双录T2",
                    "childern": null
                  },
                  {
                    "key": "865501",
                    "value": "测试双录T300",
                    "childern": null
                  },
                  {
                    "key": "865502",
                    "value": "测试双录T302变",
                    "childern": null
                  },
                  {
                    "key": "8666",
                    "value": "预生产考核分公司",
                    "childern": null
                  },
                  {
                    "key": "866601",
                    "value": "测试123",
                    "childern": null
                  },
                  {
                    "key": "866606",
                    "value": "预生产考核中心支公司",
                    "childern": null
                  },
                  {
                    "key": "86660606",
                    "value": "预生产考核营销服务部",
                    "childern": null
                  },
                  {
                    "key": "8668",
                    "value": "映射新增",
                    "childern": null
                  },
                  {
                    "key": "8677",
                    "value": "8677T2",
                    "childern": null
                  },
                  {
                    "key": "867701",
                    "value": "8677T3",
                    "childern": null
                  },
                  {
                    "key": "86770101",
                    "value": "867701T4",
                    "childern": null
                  },
                  {
                    "key": "8678",
                    "value": "8678T2",
                    "childern": null
                  },
                  {
                    "key": "8688",
                    "value": "8688报表测试",
                    "childern": null
                  },
                  {
                    "key": "868801",
                    "value": "868801报表",
                    "childern": null
                  },
                  {
                    "key": "86880101",
                    "value": "86880101",
                    "childern": null
                  },
                  {
                    "key": "868802",
                    "value": "868802报表",
                    "childern": null
                  },
                  {
                    "key": "86880201",
                    "value": "86880201",
                    "childern": null
                  },
                  {
                    "key": "8689",
                    "value": "报表测试二",
                    "childern": null
                  },
                  {
                    "key": "868901",
                    "value": "868901",
                    "childern": null
                  },
                  {
                    "key": "86890101",
                    "value": "86890101",
                    "childern": null
                  },
                  {
                    "key": "868902",
                    "value": "868902",
                    "childern": null
                  },
                  {
                    "key": "86890201",
                    "value": "henan ",
                    "childern": null
                  },
                  {
                    "key": "868903",
                    "value": "868903",
                    "childern": null
                  },
                  {
                    "key": "86890301",
                    "value": "86890301",
                    "childern": null
                  },
                  {
                    "key": "8697",
                    "value": "8697T2",
                    "childern": null
                  },
                  {
                    "key": "869701",
                    "value": "8697T3",
                    "childern": null
                  },
                  {
                    "key": "8698",
                    "value": "8698",
                    "childern": null
                  },
                  {
                    "key": "869801",
                    "value": "869801",
                    "childern": null
                  },
                  {
                    "key": "86980101",
                    "value": "86980101",
                    "childern": null
                  },
                  {
                    "key": "86980107",
                    "value": "****人寿86980101分公司",
                    "childern": null
                  },
                  {
                    "key": "86980108",
                    "value": "****人寿86980108分公司",
                    "childern": null
                  },
                  {
                    "key": "8699",
                    "value": "测试8699分公司",
                    "childern": null
                  },
                  {
                    "key": "869901",
                    "value": "****人寿869901分公司",
                    "childern": null
                  },
                  {
                    "key": "86990101",
                    "value": "****人寿86990101分公司",
                    "childern": null
                  },
                  {
                    "key": "86990102",
                    "value": "****人寿86990102分公司",
                    "childern": null
                  }
                ],
                "worktype": [
                  {
                    "key": "0",
                    "value": "短信联系业务员",
                    "childern": null
                  },
                  {
                    "key": "1",
                    "value": "电话联系业务员",
                    "childern": null
                  },
                  {
                    "key": "2",
                    "value": "网络联系业务员",
                    "childern": null
                  },
                  {
                    "key": "3",
                    "value": "面访业务员",
                    "childern": null
                  },
                  {
                    "key": "4",
                    "value": "短信联系客户",
                    "childern": null
                  },
                  {
                    "key": "5",
                    "value": "电话联系客户",
                    "childern": null
                  },
                  {
                    "key": "6",
                    "value": "网络联系客户",
                    "childern": null
                  },
                  {
                    "key": "7",
                    "value": "面访客户",
                    "childern": null
                  }
                ],
                "payintvs": [
                  {
                    "key": "1",
                    "value": "月交",
                    "childern": null
                  },
                  {
                    "key": "12",
                    "value": "年交",
                    "childern": null
                  }
                ]
              },
              "ipage": {
                "records": [
                  {
                    "contno": "0002035922971813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-21 00:00:00",
                    "payyear": 2,
                    "payyears": 20,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 5000,
                    "riskcode": "111102",
                    "riskname": "****人寿盛世荣华终身寿险",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002037022791813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-21 00:00:00",
                    "payyear": 2,
                    "payyears": 3,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 2000,
                    "riskcode": "212205",
                    "riskname": "****人寿惠泰鑫禧两全保险（分红型）",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002037222141813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-21 00:00:00",
                    "payyear": 2,
                    "payyears": 3,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 2000,
                    "riskcode": "212205",
                    "riskname": "****人寿惠泰鑫禧两全保险（分红型）",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002040222091813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-26 00:00:00",
                    "payyear": 2,
                    "payyears": 3,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 10000,
                    "riskcode": "111102",
                    "riskname": "****人寿盛世荣华终身寿险",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002040322251813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-26 00:00:00",
                    "payyear": 2,
                    "payyears": 5,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 13000,
                    "riskcode": "111102",
                    "riskname": "****人寿盛世荣华终身寿险",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002040422411813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-26 00:00:00",
                    "payyear": 2,
                    "payyears": 10,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 15000,
                    "riskcode": "111102",
                    "riskname": "****人寿盛世荣华终身寿险",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  },
                  {
                    "contno": "0002040522571813",
                    "appntname": "业高姆",
                    "appntid": "0000949588",
                    "paytodate": "2023-04-26 00:00:00",
                    "payyear": 2,
                    "payyears": 15,
                    "payintv": "12",
                    "payintvname": "年交",
                    "paymoney": 12000,
                    "riskcode": "111102",
                    "riskname": "****人寿盛世荣华终身寿险",
                    "agentcode": "8601010114",
                    "agentname": "赵天天",
                    "contstate": "0",
                    "reagentcode": "860100003"
                  }
                ],
                "total": "7",
                "size": "10",
                "current": "1",
                "orders": [],
                "searchCount": true,
                "pages": "1"
              }
            }
            if (res.code == 200 && res.data != null) {
              this.workType = res.data.baseMapForPlanList.worktype;
              if (res.data.ipage && res.data.ipage.total > 0) {
                if (params != 999) {
                  this.$Message.info("查询成功");
                }
                this.querySubmit = false;
                this.total = res.data.ipage.total;
                this.chargeData = res.data.ipage.records;
                this.chargeData.forEach(element => {
                  if (
                    element.payyear &&
                    element.payyears &&
                    element.payintvname
                  ) {
                    element.count =
                      element.payyear +
                      "/" +
                      element.payyears +
                      element.payintvname;
                  }
                  if (element.paytodate) {
                    element.paytodate = element.paytodate.substr(0, 10);
                  }
                  if (element.riskcode && element.riskname) {
                    element.mainRisks =
                      element.riskname + "-" + element.riskcode;
                  }
                });
              } else {
                this.querySubmit = false;
                this.total = 0;
                this.chargeData = [];
                if (params != 999) {
                  this.$Message.info("查询数据为空");
                }
              }
            } else {
              this.querySubmit = false;
              this.total = 0;
              this.chargeData = [];
              if (params != 999) {
                this.$Message.info(res.msg);
              }
            }
          });
        } else {
          this.$Message.error("信息填写有误");
        }
      });
    },

    // 分页查询
    pageSubmit() {
      this.pageObj.index = this.pageIndex;
      this.pageObj.pageSize = this.pageSize;
      this.api.getlist(this.pageObj).then(res => {
        if (res.code == 200 && res.data != null) {
          if (res.data.ipage && res.data.ipage.total > 0) {
            this.total = res.data.ipage.total;
            this.chargeData = res.data.ipage.records;
            this.chargeData.forEach(element => {
              if (element.payyear && element.payyears && element.payintvname) {
                element.count =
                  element.payyear +
                  "/" +
                  element.payyears +
                  element.payintvname;
              }
              if (element.paytodate) {
                element.paytodate = element.paytodate.substr(0, 10);
              }
              if (element.riskcode && element.riskname) {
                element.mainRisks = element.riskname + "-" + element.riskcode;
              }
            });
            this.workType = res.data.baseMapForPlanList.worktype;
          } else {
            this.total = 0;
            this.chargeData = [];
            this.$Message.info("查询数据为空");
          }
        } else {
          this.total = 0;
          this.chargeData = [];
          this.$Message.info(res.msg);
        }
      });
    },

    // 重置表单
    handleReset() {
      this.$refs.chargeForm.resetFields();
      this.chargeForm = {
        policyNo: "",
        payableDayRange: ["", ""],
        clerkName: "",
        premiumMin: "",
        premiumMax: "",
        postaladdress: '',
        payWay: '',
      };
    },

    // 单选按钮选择，其他置灰
    chargePlanTypeChange(status) {
      if (status == "应交日前") {
        this.chargePlan.beforeDayDisabled = false;
        this.chargePlan.afterDayDisabled = true;
        this.chargePlan.appointedDayDisabled = true;
        this.chargePlan.finalPlanTime = this.chargePlan.beforeDay;
      }
      if (status == "应交日后") {
        this.chargePlan.beforeDayDisabled = true;
        this.chargePlan.afterDayDisabled = false;
        this.chargePlan.appointedDayDisabled = true;
        this.chargePlan.finalPlanTime = this.chargePlan.afterDay;
      }
      if (status == "指定日期") {
        this.chargePlan.beforeDayDisabled = true;
        this.chargePlan.afterDayDisabled = true;
        this.chargePlan.appointedDayDisabled = false;
        this.chargePlan.finalPlanTime = this.chargePlan.appointedDay;
      }
    },

    // 表格多选获取数据
    selectionChange(selection) {
      this.selectionData = selection;
    },

    // 获取单选按钮中的输入框的值
    dateValue1() {
      this.chargePlan.finalPlanTime = this.chargePlan.beforeDay;
    },
    dateValue2() {
      this.chargePlan.finalPlanTime = this.chargePlan.afterDay;
    },
    dateValue3() {
      this.chargePlan.finalPlanTime = this.chargePlan.appointedDay;
    },

    PlanSubmit() {
      this.planSubmit = true;
      if (this.selectionData.length > 0) {
        if (this.chargePlan.finalPlanTime && this.chargePlan.workType) {
          let selectionDataObj = JSON.parse(JSON.stringify(this.selectionData));
          // 添加数据
          selectionDataObj.forEach(element => {
            element.plantype = 1;
            element.worktype = this.chargePlan.workType;
            if (element.paymoney) {
              element.sumprem = element.paymoney;
            } else {
              element.sumprem = '0';
            }
            // 将计划时间转化为应交日前、后的天数
            if (element.paytodate && this.chargePlan.planTime !== "指定日期") {
              element.datevlue = this.chargePlan.finalPlanTime;
              let oldTime = new Date(element.paytodate).getTime();
              let diffTime =
                this.chargePlan.finalPlanTime * 24 * 60 * 60 * 1000;
              element.appointeddate =
                this.chargePlan.planTime == "应交日前"
                  ? new Date(oldTime - diffTime)
                  : new Date(oldTime + diffTime);
              element.plandatetype =
                this.chargePlan.planTime == "应交日前" ? 0 : 1;
            } else {
              element.plandatetype = 2;
              let date1 = new Date(this.chargePlan.finalPlanTime).toJSON();
              let startDate = new Date(
                +new Date(date1) + 8 * 3600 * 1000
              ).toISOString();
              element.appointeddate = startDate;
            }
          });
          this.$emit("resetBadge");
          this.planSubmit = false;
          this.$Message.success('提交成功');
          // 循环提交
          // let index = 0;
          // selectionDataObj.forEach(element => {
          //   this.api.saveplan(element).then(res => {
          //     if (res.code == 200 && res.data != null) {
          //       index++;
          //       if (index == selectionDataObj.length) {
          //         this.$emit("resetBadge");
          //         this.handleSubmit(1);
          //         this.$Message.success(res.msg);
          //         this.planSubmit = false;
          //       }
          //     } else {
          //       index++;
          //       this.$Message.info(res.msg);
          //       if (index == selectionDataObj.length) {
          //         this.$emit("resetBadge");
          //         this.handleSubmit(1);
          //         this.planSubmit = false;
          //       }
          //     }
          //   });
          // });
        } else {
          this.planSubmit = false;
          this.$Message.info("计划时间/计划方式未录入，不可进行此操作");
          return false;
        }
      } else {
        this.planSubmit = false;
        this.$Message.info("未选择保单，不可进行此操作");
        return false;
      }
    },

    // 分页设置
    pageChange(pageIndex) {
      this.pageIndex = pageIndex;
      this.pageSubmit();
    },
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.pageSubmit();
    },

    // 转化为两位小数
    decimalConversion(value) {
      let reg = /^[0-9][0-9]*$/;
      let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
      let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
      if (value) {
        if (reg.test(value)) {
          this.chargeForm.premiumMin = value + ".00";
        } else if (reg1.test(value)) {
          this.chargeForm.premiumMin = value + "0";
        } else if (reg2.test(value)) {
        } else {
          this.$refs.chargeForm.validateField("premiumMin");
        }
      } else {
        this.chargeForm.premiumMin = null;
      }
    },

    decimalConversion2(value) {
      let reg = /^[0-9][0-9]*$/;
      let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
      let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
      if (value) {
        if (reg.test(value)) {
          this.chargeForm.premiumMax = value + ".00";
        } else if (reg1.test(value)) {
          this.chargeForm.premiumMax = value + "0";
        } else if (reg2.test(value)) {
        } else {
          this.$refs.chargeForm.validateField("premiumMax");
        }
      } else {
        this.chargeForm.premiumMax = null;
      }
    },
    draw(ele, loginUser, loginTime) {
      let imageUrl = drawSign(ele, loginUser, loginTime)
      document.getElementsByClassName("ivu-table-fixed-body")[2].style.background = 'url(' + imageUrl + ') left top repeat'
      document.getElementsByClassName("ivu-table-fixed-body")[2].classList.add("add-background")

      document.getElementsByClassName("ivu-table-body")[1].style.background = 'url(' + imageUrl + ') left top repeat'
      document.getElementsByClassName("ivu-table-body")[1].classList.add("add-background")

    },
    //交费方式
    changePayWay(value) {
      console.log(value, '交费方式', this.chargeForm.payWay);
    },
  },
  mounted() {
    this.handleSubmit(999);
    let loginUser = sessionStorage.getItem("name");
    let loginTime =
      new Date().getFullYear() +
      "/" +
      (new Date().getMonth() + 1) +
      "/" +
      (new Date().getDate());
    this.draw(this.$refs.myCanvas, loginUser, loginTime)
  },
  beforeDestroy() {
    this.chargeData = [];
    this.chargeForm = null;
    this.chargePlan = null;
    this.workType = null;
    this.chargeColumns = null;
    this.rules = null;
    this.total = null;
    this.pageSizeOptions = null;
    this.pageIndex = null;
    this.pageSize = null;
    this.pageObj = null;
    this.selectionData = null;
    this.querySubmit = null;
    this.planSubmit = null;
  }
};
</script>

<style lang="less">
@import "./index.less";
</style>